package cn.kevinking.ai.service.impl;

import cn.kevinking.ai.config.MyAnno;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClient;

import java.time.LocalDateTime;

/**
 * mcp server hello world service impl
 *
 * @author kevinking
 * @since 20 Jul 2025
 */
@MyAnno
@Service
public class HelloMcpServerService {

	private final RestClient restClient;

	public HelloMcpServerService() {
		this.restClient = RestClient.create();
	}

	private record WeatherResponse(Current current) {
		private record Current(LocalDateTime localDateTime, int interval, double temperature) {}
	}

	@Tool(description = "Get the temperature (in celsius) for a specific location")
	public String getWeather(
			@ToolParam(description = "The location latitude") double latitude,
			@ToolParam(description = "The location longitude") double longitude) {
		WeatherResponse weatherResponse = restClient.get()
				.uri("https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.41&hourly=temperature_2m")
				.retrieve()
				.body(WeatherResponse.class);
		assert weatherResponse != null;
		return weatherResponse.toString();
	}

}
